//
//  ZMYPasswLoginViewController.m
//  奇阅
//
//  Created by 奇阅科技 on 14-10-22.
//  Copyright (c) 2014年 奇阅科技. All rights reserved.
//

#import "ZMYPasswLoginViewController.h"
#import "Config.h"
@interface ZMYPasswLoginViewController ()

@end

@implementation ZMYPasswLoginViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setLeftBackButtonForNavigation];
    [self setTitleForNavigation:@"登录"];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)loginButton:(id)sender {
    if (self.userNameTextField.text.length<1||self.passwdTextField.text.length<1) {
        [AppDelegate showHUDAndHide:@"请把信息填写完整" view:self.view];
        return;
    }
    [self.userNameTextField resignFirstResponder];
    [self.passwdTextField resignFirstResponder];
    MBProgressHUD *hud = [AppDelegate showHUD:@"正在登录..." view:self.view];
    [[ZMYNetWorkAPI default]loginUsername:self.userNameTextField.text passwd:self.passwdTextField.text response:^(NSDictionary *resultDic) {
        [UserAccount removeAccount];
        [UserAccount saveAccount:[UserAccount getFromDict:resultDic]];
        [hud hide:YES];
//        [self.navigationController popToRootViewControllerAnimated:NO];
//        [[NSNotificationCenter defaultCenter] postNotificationName:@"toUserController" object:@"login"];
        [[AppDelegate delegate]goToBookRack];
    } error:^(NSString *errorStr) {
        [hud hide:YES];
        [AppDelegate showHUDAndHide:errorStr view:self.view];
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
